//
// Created by mmuee on 2024/4/30.
//
#pragma once


#ifndef PIU_CORE_PLATFORMCONFIG_HPP
#define PIU_CORE_PLATFORMCONFIG_HPP
/* clang-format off */

#define PLATFORM_UNKNOWN         0
#define PLATFORM_WIN             1
#define PLATFORM_MAC             2
#define PLATFORM_LINUX           3
#define PLATFORM_IOS             4
#define PLATFORM_ANDROID         5
#define PLATFORM_EMSCRIPTEN      6
#define PLATFORM_ESP             7

#define TARGET_PLATFORM             PLATFORM_UNKNOWN

#ifdef _WIN32
   #ifdef _WIN64
        #undef  TARGET_PLATFORM
        #define TARGET_PLATFORM PLATFORM_WIN
   #else
        #error "Unsupport win32, please change to win64 and try again"
   #endif
#elif __APPLE__
    #include <TargetConditionals.h>
    #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
        #undef  TARGET_PLATFORM
        #define TARGET_PLATFORM PLATFORM_IOS
    #elif TARGET_OS_MAC
        #undef  TARGET_PLATFORM
        #define TARGET_PLATFORM PLATFORM_MAC
    #endif
#elif __ANDROID__
    #undef  TARGET_PLATFORM
    #define TARGET_PLATFORM PLATFORM_ANDROID
#elif __linux__
    #undef  TARGET_PLATFORM
    #define TARGET_PLATFORM PLATFORM_LINUX
#elif __EMSCRIPTEN__
    #undef  TARGET_PLATFORM
    #define TARGET_PLATFORM PLATFORM_ESP
#elif ESP_PLATFORM

#else
    #error "Unknown compiler"
#endif

#define IS_PLATFORM(p)      (TARGET_PLATFORM == p)
#define NOT_PLATFORM(p)     (!(IS_PLATFORM(p)))


// check platform
#if !TARGET_PLATFORM
    #error  "Unsupported Platform!"
#endif

#if ((TARGET_PLATFORM == PLATFORM_ANDROID) || (TARGET_PLATFORM == PLATFORM_IOS))
    #define PLATFORM_MOBILE
#endif

/* clang-format on */
#endif //PIU_CORE_PLATFORMCONFIG_HPP
